<?php 
	class CategoryController extends Controller{

		public $model;
		public $category;

		public function __init(){
			$this->model = K('category');
			$this->category = $this->model->getTreeData();

		}
		public function index(){
			
			// $category = $this->model->getCategory();
			$this->assign('category',$this->category);
			$this->display();
		}

		// 添加栏目的操作
		public function add(){
			if(IS_POST){
				if($this->model->addData()){
					$this->success('添加成功了呗');
				}else{
					$this->error($this->model->error);
				}
			}else{
				$this->assign('category',$this->category);
			
				$this->display();
			}
		}
		

		public function edit(){
			// echo "string";
			if(IS_POST){
				if($this->model->saveData()){
					$this->success('编辑成功');
				}else{
					$this->error($this->model->error);
				}

			}else{

				$category = $this->model->getEditData();
				$data = $this->model->getDataByCid();
				// 分配数据
				$this->assign('category',$category);
				$this->assign('data',$data);
				$this->display();
			}
			
		}



	}





 ?>